package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.MeetingRoomMaintainPageQueryDTO;
import com.sky.dto.MeetingRoomStatusPageQueryDTO;
import com.sky.entity.MeetingRoom;
import com.sky.mapper.MeetingRoomMaintainMapper;
import com.sky.mapper.MeetingRoomStatusMapper;
import com.sky.result.PageResult;
import com.sky.service.MeetingRoomMaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MeetingRoomMaintainServiceImpl implements MeetingRoomMaintainService {

    @Autowired
    private MeetingRoomMaintainMapper meetingRoomMaintainMapper;

    @Override
    // 分页查询会议室状态
    public PageResult pageQuery(MeetingRoomMaintainPageQueryDTO meetingRoomMaintainPageQueryDTO) {
        // 设置分页参数
        PageHelper.startPage(meetingRoomMaintainPageQueryDTO.getPage(),meetingRoomMaintainPageQueryDTO.getPageSize());   //设置分页查询参数

        // 调用mapper查询数据
        Page<MeetingRoom> page = meetingRoomMaintainMapper.pageQuery(meetingRoomMaintainPageQueryDTO);

        Long total=page.getTotal(); // 满足条件的总记录数
        List<MeetingRoom> meetingRoomList=page.getResult(); //满足条件的所有记录

        return new PageResult(total,meetingRoomList);
    }

    // 呼叫清洁工打扫会议室
    @Override
    public boolean callCleaner(Long id) {
        meetingRoomMaintainMapper.updateMeetingRoomStatus(id);
        return true;
    }

    // 呼叫维修工修理会议室
    @Override
    public boolean callRepairman(Long id) {
        meetingRoomMaintainMapper.updateMeetingRoomStatus(id);
        return true;
    }
}
